<script>
export default {
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: function () {
    console.log('App Show')
    
    // 检查登录状态
    const isLoggedIn = !!uni.getStorageSync('token');
    const currentPath = this.getCurrentPagePath();
    
    // 允许投资历史相关页面在无登录状态下访问
    const allowedPagesWithoutLogin = ['/pages/login/login', '/pages/history/history', '/pages/history/add', '/pages/history/detail'];
    
    // 如果未登录且不在允许的免登录页面列表中，重定向到登录页
    if (!isLoggedIn && !allowedPagesWithoutLogin.includes(currentPath)) {
      uni.redirectTo({
        url: '/pages/login/login'
      });
    }
  },
  onHide: function () {
    console.log('App Hide')
  },
  methods: {
    // 获取当前页面路径
    getCurrentPagePath() {
      const pages = getCurrentPages();
      if (pages.length > 0) {
        return pages[pages.length - 1].route;
      }
      return '';
    }
  }
}
</script>

<style>
/*每个页面公共css */

/* 全局字体设置 - 适合手机端阅读 */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #333;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 文本优化 */
text {
  -webkit-user-select: none;
  user-select: none;
}

/* 确保页面内容不被tabBar遮挡 */
.page {
  padding-bottom: 60px;
}
</style>
